
EvaluateScript("menu_custom.js");

function map2screenX(X)
{
	if (GetScreenWidth()/2 < GetCameraX())
		if (GetCameraX() > GetLayerWidth(0)*16 - GetScreenWidth()/2)
			return GetScreenWidth() - (GetLayerWidth(0)*16 - X);
		else return GetScreenWidth()/2 + (X - GetCameraX());
	else return X; 
}

function map2screenY(Y)
{
	if (GetScreenHeight()/2 < GetCameraY())
		if (GetCameraY() > GetLayerHeight(0)*16 - GetScreenHeight()/2)
			return GetScreenHeight() - (GetLayerHeight(0)*16 - Y);
		else return GetScreenHeight()/2 + (Y - GetCameraY());
	else return Y;
}

function restrictCamY(bound)
{
	DetachCamera(); SetCameraX(GetPersonX(thePC.name)); SetCameraY(bound);
}

function isdude(whom)
{
	var cheez = GetPersonList();
	for (var g=0; g<cheez.length; g++)
		if (cheez[g]==whom) return true;
	return false;
}


	/* DEBUG STUFF */

/* AMAZING SPRITE DUDE! */

function spritedude(dood)
{
	if (isdude("spritetester")) DestroyPerson("spritetester");
	spritetester = new retard("spritetester", dood, true);
	SetPersonX("spritetester", 327);
	SetPersonY("spritetester", 183);
	SetPersonScript("spritetester", 3, "talkjunk('SPRITE: Hello, sir! Get outta here!');");
	SetPersonScript("spritetester", 4, "if (spritetester.step > spritetester.dirs.length) spritetester.step=0; walkgay(spritetester, spritetester.dirs[spritetester.step]);");
	spritetester.dirs = new Array('fd', 'd', 'd', 'fr', 'r', 'r', 'fu', 'u', 'u', 'fl', 'l', 'l');
	IgnoreTileObstructions("spritetester", true);
	people = GetPersonList();
}

function testspritemenu()
{
	var rssmen = new CMenu("Choose your subject!");
	var thersss = GetFileList("spritesets");
	for (var m=0; m<thersss.length; m++)
		rssmen.addItem(thersss[m], "spritedude('" + thersss[m] + "');");
	rssmen.execute(xbo, 35+ybo, 320-xbo*2, 240-ybo*2-35);
}


function eventviewmenu()
{
	var eventmen = new CMenu("View your past...");
	eventmen.addItem("Beginning", "eventBox['scene1'].play(true)", "Still Evil.");
	eventmen.addItem("Gimms Introduction", "eventBox['gimms_scene'].play(true)", "The helpless mascot.");
	eventmen.addItem("Court Trial", "eventBox['court_scene'].play(true)", "The Trial.");
	eventmen.addItem("Exag.Scene1/Testimony2", "eventBox['exag_scene1'].play(true)", "The rich man is mugged.");
	eventmen.addItem("Exag.Scene2/Test3", "eventBox['exag_scene2'].play(true)", "The merchant is assaulted.");
	eventmen.addItem("Exag.Scene3/Test4", "eventBox['exag_scene3'].play(true)", "Chococart attack.");
	eventmen.addItem("Exag.Scene4/Test5", "eventBox['exag_scene4'].play(true)", "Operation: Piano Drop.");
	eventmen.addItem("Exag.Scene5/Adjourn", "eventBox['exag_scene5'].play(true)", "Old Man's time is up.");
	eventmen.addItem("Bust In Jail", "eventBox['jail_scene'].play(true)", "A thousand years behind bars.");
	eventmen.addItem("Flashback", "eventBox['flashback_scene'].play(true)", "Straight from the makers of FF6.");
	eventmen.addItem("Bust Out Jail", "eventBox['jail_cont_scene'].play(true)", "Still Evil.");
	
	
	eventmen.addItem("Bust Out Jail 2", "eventBox[\"chase2\"].play(true)", "Part 2.");
	eventmen.addItem("New house", "eventBox[\"newhouse\"].play(true)", "Kefka finds a new house.");
	eventmen.addItem("Get that furniture!", "eventBox[\"furniture_mission\"].play(true)", "NOW!");
	eventmen.addItem("Kefka's Dream", "eventBox[\"kefka_dream1\"].play(true)", "Sleepy head.");
	eventmen.addItem("The morning after", "eventBox[\"morning_after\"].play(true)", "Yawn.");
	
	
	eventmen.execute(xbo, 50+ybo, 320-xbo*2, 240-ybo*2-50);
}

function debugMenu()
{
	var debugmenu = new CMenu('Where do you want to go?');

	debugmenu.addItem("Albrook", "thempa = 'Albrook.rmp';", "The main town.");
	debugmenu.addItem(" -House 1", "thempa = 'Aresidence1.rmp';", "Est. 1997.");
	debugmenu.addItem(" -House 2", "thempa = 'Aresidence2.rmp';", "The busiest place on the planet.");
	debugmenu.addItem(" -House 2 - F2 (m0rd)", "thempa = 'Aresidence2up.rmp';", "See how it's done.");
	debugmenu.addItem(" -House 3", "thempa = 'Aresidence3.rmp';", "Visit the wealthy.");
	debugmenu.addItem(" -House 3 - Kitchen", "thempa = 'Aresidence3kit.rmp';", "Dine or Die!");
	debugmenu.addItem(" -House 3 - F2", "thempa = 'Aresidence3up.rmp';", "Luxury Addiction.");
	debugmenu.addItem(" -House 4", "thempa = 'Aresidence4.rmp';", "Maddening Property Tax.");
	debugmenu.addItem(" -House 5", "thempa = 'Aresidence5.rmp';", "Chat of Spectrum Opposites.");
	debugmenu.addItem(" -House 6", "thempa = 'Aresidence6.rmp';", "Familiar Foes.");
	debugmenu.addItem(" -House 6 - F2", "thempa = 'Aresidence6up.rmp';", "Damn kids.");
	debugmenu.addItem(" -House 7", "thempa = 'Aresidence7.rmp';", "Employee mayhem.");
	debugmenu.addItem(" -Old Man's House", "thempa = 'Oldshouse.rmp';", "No TV? What does he watch?");
	debugmenu.addItem(" -GIMM's House", "thempa = 'Gimmsplace.rmp';", "Burger flipping provides stable living.");
	debugmenu.addItem(" -GIMM's House F2", "thempa = 'Gimmsupstairs.rmp';", "Promotion!");
	debugmenu.addItem(" -Vacant House 1", "thempa = 'Auhouse1.rmp';", '"It\'s a madhouse!"');
	debugmenu.addItem(" -Vacant House 1 - F2", "thempa = 'Auhouse1up.rmp';", "Palazzo's Palace.");
	debugmenu.addItem(" -Vacant House 2", "thempa = 'Auhouse2.rmp';", "Books for Crooks.");
	debugmenu.addItem(" -Vacant House 2 - F2", "thempa = 'Auhouse2up.rmp';", "Revenge-inciting Library.");
	debugmenu.addItem(" -Vacant House 3", "thempa = 'Auhouse3.rmp';", "Inhabited by Scum.");
	debugmenu.addItem(" -Vacant House 4", "thempa = 'Auhouse4.rmp';", "Not a bad place...");
	debugmenu.addItem(" -Vacant House 4 - F2", "thempa = 'Auhouse4up.rmp';", "Fit for a King?");
//	debugmenu.addItem(" -Kefka's House: K's Room", "thempa = 'Kroom.rmp';", "Palazzo's Palace.");
//	debugmenu.addItem(" -Kefka's House: Vicks' Room", "thempa = 'Vroom.rmp';", "Babes.");
//	debugmenu.addItem(" -Kefka's House: Wedge's Room", "thempa = 'Wroom.rmp';", "Dudes.");
	debugmenu.addItem(" -Mayor's House", "thempa = 'Mayorshouse.rmp';", "He's actually a dictator.");
	debugmenu.addItem(" -Mayor's House: 2nd Floor", "thempa = 'Mayorsupstairs.rmp';", "Bow to the throne.");
	debugmenu.addItem(" -Mayor's House: Basement", "thempa = 'Mayorsbasement.rmp';", '"..?"');
	debugmenu.addItem(" -Wiz's Hizzouse", "thempa = 'Wizhousef1.rmp';", "Hopefully an F1 jet will land here.");
	debugmenu.addItem(" -Wiz's Hizzouse: 2nd Floor", "thempa = 'Wizhousef2.rmp';", "Hopefully an F2 tornado will land here.");
	debugmenu.addItem(" -Albrook Alleyway", "thempa = 'Albrookalley.rmp';", "The bowels of supremacy.");
	debugmenu.addItem(" -Albrook Sewer", "thempa = 'Albrookalley.rmp';", "The bowels of supremacy.");
	debugmenu.addItem(" -Tower A - F1", "thempa = 'Atower1.rmp';", "Needs a clerk.");
	debugmenu.addItem(" -Tower A - F2", "thempa = 'Atower2.rmp';", "Needs an interior designer.");
	debugmenu.addItem(" -Tower A - F3", "thempa = 'Atower3.rmp';", "Needs a terrorist attack.");
	debugmenu.addItem(" -Tower A - F4", "thempa = 'Atower4.rmp';", "Needs an elevator.");
	debugmenu.addItem(" -Tower A - F2 Apt", "thempa = 'AptThief.rmp';", "Rent covered with threats.");
	debugmenu.addItem(" -Tower A - F3 Apt", "thempa = 'AptDooz.rmp';", "Feast of the Beast.");
	debugmenu.addItem(" -Tower A - F4 Apt", "thempa = 'AptLoser.rmp';", "He thinks it\'s the penthouse.");
	debugmenu.addItem(" -Tower B - F1", "thempa = 'Btower1.rmp';", "The secondary tower. (!)");
	debugmenu.addItem(" -Factory - F1", "thempa = 'Afactory1.rmp';", "Production of Waste.");
	debugmenu.addItem(" -Factory - F2", "thempa = 'Afactory2.rmp';", "CEO of sweatshopping.");
	debugmenu.addItem(" -ChocoStore", "thempa = 'Chocostore.rmp';", "Buy one today!");
	debugmenu.addItem(" -Toy Store", "thempa = 'Toystore.rmp';", "Ages 6 and up.");
	debugmenu.addItem(" -Cafebar", "thempa = 'Cafebar.rmp';", '"It\'s time to party!"');
	debugmenu.addItem(" -Magitek Store", "thempa = 'Magitechstore.rmp';", "You can't afford it.");
	debugmenu.addItem(" -McMoogle's", "thempa = 'Mcmoogles.rmp';", "Restaurant rivalry.");
	debugmenu.addItem(" -Trishop", "thempa = 'Trishop.rmp';", "Where to shoplift.");
	debugmenu.addItem(" -Chocobo Delivery Service", "thempa = 'CDS.rmp';", "9.99 GP Warping + Handling");
	debugmenu.addItem(" -Court Room", "thempa = 'Court.rmp';", "Flip off the judge.");
	debugmenu.addItem(" -Court House", "thempa = 'Courthouse.rmp';", "Break and Enter.");
	debugmenu.addItem(" -Guard Station", "thempa = 'Jailhouse.rmp';", "Sit back and relax at this worry-free suite!");
	debugmenu.addItem(" -Jail", "thempa = 'Jail.rmp';", "Point and laugh at the inmates!");
	
	debugmenu.addItem("Albrook Forest", "thempa = 'Aforest1.rmp';", "Start a forest fire!");
	debugmenu.addItem(" -Albrook Forest2", "thempa = 'Aforest2.rmp';", "Start two forest fires!");
	debugmenu.addItem(" -Albrook Forest3", "thempa = 'Aforest3.rmp';", "Just burn it all!");
	debugmenu.addItem(" -Albrook Forest4", "thempa = 'Aforest4.rmp';", "...It never ends!");
	
	debugmenu.addItem("Tower Ruins", "thempa = 'TowerRuines.rmp';", "Took more than terrorism for this baby.");
	debugmenu.addItem("Tower Ruins Hut", "thempa = 'Towerruinsjunkhut.rmp';", "Java the junk. ");
	
	debugmenu.addItem("Thamasa", "thempa = 'Thamasa.rmp';", "Thomas aah!");
	
	debugmenu.addItem("Nikeah", "thempa = 'Nikeah.rmp';", "Nike yaah! ");
	debugmenu.addItem(" -Choco", "thempa = 'Nikeachoco.rmp';", "Chocobo Stability.");
	debugmenu.addItem(" -Coffee", "thempa = 'Nikeahcofee.rmp';", "Junk the java.");
	debugmenu.addItem(" -Inn", "thempa = 'Nikeahinn.rmp';", "Innuendo!");
	debugmenu.addItem(" -Magic Sto'", "thempa = 'Nikeahmagic.rmp';", "Buy some spellbinders.");
	debugmenu.addItem("           -Lv2", "thempa = 'Nikeahupsmagic.rmp';", "Induction of seduction.");
	
	debugmenu.addItem("Narshe", "thempa = 'Narshe.rmp';", "Narshe is harshe.");
	debugmenu.addItem(" -Armory", "thempa = 'Narshearmy.rmp';", "Arm yourself dont harm yourself.");
	debugmenu.addItem(" -Armor Shop", "thempa = 'Narshearm.rmp';", "Get armored plating for your ride.");
	debugmenu.addItem(" -Arvis' Pad", "thempa = 'Narshebarks.rmp';", "Biggest party house in town! ");
	debugmenu.addItem(" -Inn", "thempa = 'Narsheinn.rmp';", "Innigger Integer.");
	debugmenu.addItem(" -Kupo Club", "thempa = 'Narshekc.rmp';", "Hot moogle action.");
	debugmenu.addItem(" -Elder's Pad", "thempa = 'Narsheld.rmp';", "Tactical Operations Center.");
	debugmenu.addItem(" -Pa's House of Ho's", "thempa = 'Narshelove.rmp';", "Pimpin the grannies.");
	debugmenu.addItem(" -Lame house", "thempa = 'Narshers.rmp';", "Cozy like a foxhole.");
	debugmenu.addItem(" -Tonberry King", "thempa = 'Narshetk.rmp';", "Chefs with a grudge.");
	debugmenu.addItem(" -Small room", "thempa = 'Narshews.rmp';", "Out before you're in?");
	debugmenu.addItem(" -Wash room", "thempa = 'Narshewsrm.rmp';", "Narsh Warshe room.");
	
	debugmenu.addItem(" Jidoor Cheese Shop", "thempa = 'Jidoorcheese.rmp';", "Ultimate Cheddar Mix, plz.");
	
	debugmenu.addItem("Zozo", "thempa = 'Zozo.rmp';", "Zozo has no Ozone, bozo.");
	
	
	debugmenu.addItem("Figaro Castle", "thempa = 'Figarocastle.rmp';", "Smoke a Cigaro and play Guitaro.");
	debugmenu.addItem(" -Corridor", "thempa = 'Figarocorridor.rmp';", "Mordor?");
	debugmenu.addItem(" -East Corridor", "thempa = 'Figaroeastcorridor.rmp';", "Quit rhyming you lamer.");
	debugmenu.addItem(" -East Tower", "thempa = 'Figaroeasttower.rmp';", "Tower above the middle-class.");
	debugmenu.addItem(" -Hall", "thempa = 'Figarohall.rmp';", "Royal Pineapples.");
	debugmenu.addItem(" -Infirmary", "thempa = 'Figaroinfirmary.rmp';", "What do you infer, Mary? AIDS!");
	debugmenu.addItem(" -Library", "thempa = 'Figarolibrary.rmp';", "Shh!");
	debugmenu.addItem(" -Prison", "thempa = 'Figaroprison.rmp';", "Freaks on exhibition.");
	debugmenu.addItem(" -Shop1", "thempa = 'Figaroshop1.rmp';", "Shop til you drop dead.");
	debugmenu.addItem(" -Shop2", "thempa = 'Figaroshop2.rmp';", "Great discounts, if nobody sees you.");
	debugmenu.addItem(" -Control room", "thempa = 'Figaroolsmobile.rmp';", "It's not an oldsmobile.");
	debugmenu.addItem(" -Throne", "thempa = 'Figarothroneroom.rmp';", "Sit on it.");
	debugmenu.addItem(" -Upstairs", "thempa = 'Figaroupstairs.rmp';", "Fall down and break your crown.");
	debugmenu.addItem(" -West Corridor", "thempa = 'Figarowestcorridor.rmp';", "The sequel to West Wing?");
	debugmenu.addItem(" -West Tower", "thempa = 'Figarowesttower.rmp';", "Westsiieede!");
	
	debugmenu.addItem("Esperville", "thempa = 'Espervill.rmp';", "Skeletons of Society.");
	
	debugmenu.addItem("Cliff", "thempa = 'cliff.rmp';", "Depressed? Take a leap!");
	debugmenu.addItem("Debug Room", "thempa = 'Debugroom.rmp';", "You'll never get there.");
	debugmenu.addItem("Desert", "thempa = 'Desert.rmp';", "Brrrr..");
	debugmenu.addItem("Doma", "thempa = 'Doma.rmp';", "Watch men rebuild their destroyed home.");
	debugmenu.addItem("Lonell", "thempa = 'Lonell.rmp';", '"Lonell."');
	debugmenu.addItem("Magitech Lab", "thempa = 'Mtektestroom.rmp';", "Experimented on like a play thing.");
	debugmenu.addItem("Magitech Lab's Elevator", "thempa = 'Elevinf.rmp';", "Descent of DOOM.");
	debugmenu.addItem("Misc. Store", "thempa = 'Miscstore.rmp';", "Thrifty.");
	debugmenu.addItem("MTek Test Room", "thempa = 'Mtektestroom.rmp';", "Test tubes!");
	
	debugmenu.addItem("Narshe", "thempa = 'Narshe.rmp';", "Narshe's freedom depends on YOU! :(");
	
	debugmenu.addItem("South Figaro", "thempa = 'Southfigaro.rmp';", "Cider House Rosebud.");
	
	debugmenu.addItem("SS Barnacles", "thempa = 'Ssbarnacles1.rmp';", "Cruise to Death.");
	debugmenu.addItem("SS Barnacles: Game Room", "thempa = 'Ssbarnacles2.rmp';", "Suffused with that old people smell.");
	debugmenu.addItem("SS Barnacles: Gift Shop", "thempa = 'Ssbarnacles3.rmp';", "What the Heck?");
	debugmenu.addItem("SS Barnacles: Main Hall", "thempa = 'Ssbarnacles4.rmp';", "I LOVE the Poop Deck.");
	debugmenu.addItem("SS Barnacles: Sleeping Quarters", "thempa = 'Ssbarnacles5.rmp';", "Pirates are NOT gay.");
	debugmenu.addItem("SS Barnacles: Captain's Room", "thempa = 'Ssbarnacles6.rmp';", "Full of Rum and Parrot Feed.");
	debugmenu.addItem("SS Barnacles: Engine Room", "thempa = 'Ssbarnacles7.rmp';", "A Bird Powered Ship.");
	
	debugmenu.addItem("Tzen", "thempa = 'Tzen.rmp';", "Town of peasants.");
	debugmenu.addItem(" -Tzen Armor Shop", "thempa = 'Tzenashop.rmp';", "Peasants' Protection.");
	debugmenu.addItem(" -Tzen Inn", "thempa = 'Tzeninn.rmp';", "Sleep with guns under your pillow.");
	debugmenu.addItem(" -Tzen Item Shop", "thempa = 'Tzenishop.rmp';", "Purchase goods but not services.");
	debugmenu.addItem(" -Tzen Mansion", "thempa = 'Tzenrichyrich.rmp';", "The biggest peasant.");
	debugmenu.addItem(" -Tzen Mansion Basement", "thempa = 'Tzenrichyrichbasement.rmp';", "The underworld.");
	debugmenu.addItem(" -Tzen Relic Shop", "thempa = 'Tzenrshop.rmp';", "Expensive things.");
	debugmenu.addItem(" -Tzen Weapon Shop", "thempa = 'Tzenwshop.rmp';", "Weapons run this world.");
	
	debugmenu.addItem("The World Map", "thempa = 'Worldmap.rmp';", "A Barren Paradise.");
	debugmenu.addItem("Chrismas BS", "thempa = 'Chrismas.rmp';", "Land of gheys.");
	debugmenu.addItem("Chrismas BS", "thempa = 'Zozo.rmp';", "Land of gheys.");
	debugmenu.addItem("The Tower Ruins", "thempa = 'TowerRuines.rmp';", "Glory in Shambles.");
	debugmenu.addItem("Figaro Castle", "thempa = 'Figarocastle.rmp';", "Tree's fukking lazy.");
	debugmenu.execute(xbo, 50+ybo, 320-xbo*2, 240-ybo*2-50);
}


function battlemenu()
{
	var batmen = new CMenu('Die by whose hand?');	//batmans
	var monstahs = OpenFile("monster.dat").read("monsterlist","").split(",");
	for (var q=0; q<monstahs.length; q++)
	batmen.addItem(monstahs[q], "battle(sologroup('" + monstahs[q] + "'))");
	for (var g=0; g<thegrouplist.length; g++)
	batmen.addItem2(thegrouplist[g], "battle(choosegroup(" + g + "))");
	batmen.execute(xbo, 35+ybo, 320-xbo*2, 240-ybo*2-35);
}



function anime()
{
	var animmenu = new CMenu("Animation",true);
	animmenu.addItem("Spritesets", "jap_anime()");
	animmenu.addItem("Attack Animations", "bat_anime()");
	animmenu.addItem("Magic Effects", "mag_anime()");
	animmenu.execute(xbo, 35+ybo, 320-xbo*2, 240-ybo*2-35);
}

function bat_anime()
{
	var rainmen = new CMenu("Battle Animations",true);
	rainmen.addItem("NOT YET!",";");
	rainmen.execute(xbo, 35+ybo, 320-xbo*2, 240-ybo*2-35);
}

function mag_anime()
{
	var sexplode = new CMenu("Magic Animations",true);
	sexplode.addItem("NOT YET!",";");
	sexplode.execute(xbo, 35+ybo, 320-xbo*2, 240-ybo*2-35);
}

function jap_anime()
{
	var assmenu = new CMenu("Choose the Spriteset",true);
	var thersss = GetFileList("spritesets",true);
	for (var m=0; m<thersss.length; m++)
		assmenu.addItem(thersss[m], "jap_anime2('" + thersss[m] + "');");
	assmenu.execute(xbo, 35+ybo, 320-xbo*2, 240-ybo*2-35);
}

function jap_anime2(supersprite)
{
	//do sheeit!
	var hugedude = LoadSpriteset(supersprite);
	var crazy = new CMenu(supersprite+": Select the Dir!",true);
	for (var f=0; f<hugedude.directions.length; f++)
		crazy.addItem(hugedude.directions[f].name, "displayANIM(LoadSpriteset('"+ supersprite +"'),"+f+")");
	crazy.execute(xbo, 35+ybo, 320-xbo*2, 240-ybo*2-35);		
}

function displayANIM(spr, dr)
{
	var framer = 0;
	var clock = GetTime();
	var barrier = GetTime();
	while (AreKeysLeft()) GetKey();
	while (!IsAnyKeyPressed() || barrier+1000>GetTime())
	{
		spr.images[spr.directions[dr].frames[framer].index].blit(160-spr.images[spr.directions[dr].frames[framer].index].width/2, 120-spr.images[spr.directions[dr].frames[framer].index].height/2);
		if (clock + 176 < GetTime()){ framer++; clock = GetTime(); }
		if (framer == spr.directions[dr].frames.length) framer=0;
		FlipScreen();
	}
	while (AreKeysLeft()) GetKey();
}


function facemenu()
{
	ApplyColorMask(Black);
	window.drawWindow(xbo, ybo, 320-xbo*2, 240-ybo*2);
	window2.drawWindow(xbor, 13, 320-xbor*2, 15);
	window2.drawWindow(xbor*2-7, 50, 110, 100);
	alphagrad.blit(0,0);
	font.drawText(100, 16, "Instant Surgery");
	var spritedudes = new Array();
	for (var g=0; g<charlist.length; g++)
	{
		var damnspr = LoadSpriteset(charstats[charlist[g]].rss);
		for (var r=0; r<damnspr.directions.length; r++)
			if (damnspr.directions[r].name == "south")
				spritedudes[g] = damnspr.images[damnspr.directions[r].frames[0].index];
	}
	//draw all dudes in a rectangle
	for (var row=0; row<5; row++)
		for (var col=0; col<5; col++)
			if (spritedudes[row*5+col]) spritedudes[row*5+col].blit(140+col*32, 50+row*30);
			
	var backer = GrabImage(0,0,320,240);
	var underknife = true;
	var row=0, col=0;
	var mode = 0;	//0: choose dude, 1: choose face
	var theman = 0;
	var magesi = GetFileList("images");
	var facelifst = new Array();
	for (var mf = 0; mf<magesi.length; mf++)
		if (magesi[mf][0]=="F" && magesi[mf][1]=="a" && magesi[mf][2]=="c" && magesi[mf][3]=="e")
			facelifst.push(magesi[mf]);
	var placeholder = 0;
	var checkcurrent = true;
	var faces = new Array();
	var getImage = function(face)
	{
		if (face in faces) return faces[face];
		else return (faces[face] = LoadImage(face));
	}
	
	while (underknife)
	{	
		backer.blit(0,0);
		pointer.blit(130+col*32, 50+row*30);
		if (mode==1)
		{
			if (checkcurrent)
			{
				placeholder = 0;
				for (var b=0; b<facelifst.length; b++)
					if (charstats[charlist[theman]].facepic == facelifst[b])
						placeholder = b;
				checkcurrent = false;
			}
			getImage(facelifst[placeholder]).blit(40,70);
		}
		FlipScreen();
		if (AreKeysLeft())
		{
			if (mode==0)
			{
			switch (GetKey())
			{
				case key_cancel:	{ underknife = false; break; }
				case KEY_RIGHT:	{ if (col<4) col++; break; }
				case KEY_LEFT:		{ if (col>0) col--; break; }
				case KEY_DOWN:	{ if (row<4) row++; break; }
				case KEY_UP:		{ if (row>0) row--; break; }
				case key_talk:		{ theman = row*5+col; mode = 1; checkcurrent=true; break; }
			}
			}
			else if (mode==1)
			{
			switch (GetKey())
			{
				case key_cancel:	{ mode=0; break; }
				case KEY_RIGHT:	{ if (placeholder < facelifst.length-1) placeholder++; else placeholder=0; break; }
				case KEY_LEFT:		{ if (placeholder > 0) placeholder--; else placeholder = facelifst.length-1; break; }
				case key_talk:		{ charstats[charlist[theman]].facepic = facelifst[placeholder]; mode = 0; break; }
			}
			}
		}	
	}	

}


function toiletguy()
{
	if (!mrtoilet.open)
	{
		dooropen.play(false);
		SetTile(2,10,1,0); SetTile(2,11,0,142);
		mrtoilet.open = true;
		SetPersonY('mcjohn', 10.5*16+7);
		var reac = GetTime() - mrtoilet.time;
		mrtoilet.hinge++;
		mrtoilet.time = GetTime();
		var slam = 33;
			if (reac < 51) slam = 2;
		else if (reac < 201) slam = 5;
		else if (reac < 401) slam = 10;
		else if (reac < 701) slam = 20;
		else if (reac < 801) slam = 30;
		else if (reac > 1001) slam = 40;
		SetDelayScript(slam/mrtoilet.hinge+5, 'SetPersonY(mcjohn.name, 10.5*16+4); SetTile(2,10,1,50); SetTile(2,11,0,49); doorclose.play(false); mrtoilet.open = false;');
	}
}

function runawaygirl()
{
	if (annoyinggirl.pointah) return;	//used as justtalked
	talkjunk("GIRL: EEK! Pirates!");
	if (annoyinggirl.qpos==0)
	{
		annoyinggirl.dirs = ['fu', 'u','for (var b=0; b<8; b++)QueuePersonCommand("annoyinggirl", pcmu, 0);', 'fl', 'l','fr', 'annoyinggirl.pointah=false;'];
		annoyinggirl.step=0; annoyinggirl.mark=0; annoyinggirl.pointah=true;
		annoyinggirl.qpos++;
		return;
	}
	if (annoyinggirl.qpos == 1)
	{
		if (GetPersonDirection(thePC.name)=="west")
		{
			annoyinggirl.dirs = ['fu','u','for(var b=0;b<8;b++)QueuePersonCommand("annoyinggirl",pcmu,0);', 'fd', 'annoyinggirl.pointah=false;'];
			annoyinggirl.qpos++;
		}
		else
		{
			annoyinggirl.dirs = ['fr','r','r','fl', 'annoyinggirl.pointah=false;'];
			annoyinggirl.qpos = 4;
		}
	}
	else if (annoyinggirl.qpos==2)
	{
		if (GetPersonDirection(thePC.name)=="north")
		{
			annoyinggirl.dirs = ['fr','r','r','fl', 'annoyinggirl.pointah=false;'];
			annoyinggirl.qpos++;	
		}
		else
		{
			annoyinggirl.dirs = ['fd','d','for(var b=0;b<8;b++)QueuePersonCommand("annoyinggirl",pcmd,0);', 'fu', 'annoyinggirl.pointah=false;'];
			annoyinggirl.qpos = 1;
		}
	}
	else if (annoyinggirl.qpos==3)
	{
		if (GetPersonDirection(thePC.name)=="east")
		{
			annoyinggirl.dirs = ['fd','d','for(var b=0;b<8;b++)QueuePersonCommand("annoyinggirl",pcmd,0);', 'fu', 'annoyinggirl.pointah=false;'];
			annoyinggirl.qpos++;
		}
		else
		{
			annoyinggirl.dirs = ['fl','l','l','fr', 'annoyinggirl.pointah=false;'];
			annoyinggirl.qpos = 2;
		}
	}
	else if (annoyinggirl.qpos==4)
	{
		if (GetPersonDirection(thePC.name)=="south")
		{
			annoyinggirl.dirs = ['fl','l','l','fr', 'annoyinggirl.pointah=false;'];
			annoyinggirl.qpos = 1
		}
		else
		{
			annoyinggirl.dirs = ['fu','u','for(var b=0;b<8;b++)QueuePersonCommand("annoyinggirl",pcmu,0);', 'fd', 'annoyinggirl.pointah=false;'];
			annoyinggirl.qpos = 3;
		}
	}
	annoyinggirl.step=0; annoyinggirl.mark=0; annoyinggirl.pointah=true;
}

function ExitMenu()
{
	window.drawWindow(xbo, ybo, 170, 38);
	font.drawText(10, 10, "Discontinue game play??");
	font.drawText(20, 20, "-Reset");
	font.drawText(20, 30, "-Exit for good.");
	font.drawText(20, 40, "-Nevermind, this rules!");
	var ydude = 2;
	var grabber = GrabImage(0,0,320,240);
	do {
		grabber.blit(0,0);
		pointer.blit(5, 20+ydude*10);
		FlipScreen();
		switch (GetKey())
		{
			case KEY_UP: 	{ if (ydude==0) ydude = 2; else ydude--; break;}
			case KEY_DOWN: { if (ydude==2) ydude=-0; else ydude++; break;}
		}
	} while (!IsKeyPressed(key_talk))
	if (ydude == 1) Abort("GAME OVER YOU QUITTER");
	else if (ydude==0) RestartGame();
	else return;
}

/*  DUDE MENUS! */

function blackmarkshop()
{
	var thashop = new CMenu("Buy somethin' you cheapskate!");
	thashop.addItem("Tonic", "items['tonic'].quantity++; money-=50;", "Restores an unworthy amount of HP.");
	thashop.addItem("Potion", "items['potion'].quantity++; money-=100;", "Restores a reasonable amount of HP.");
	thashop.addItem("Phoenix Down", "items['phoenix_down'].quantity++; money-=150;", "Restores an unworthy life.");
	thashop.addItem("Eye Drop", "items['eye_drop'].quantity++; money-=50;", "Restores certain status ailment.");
	thashop.addItem("Antidote", "items['antidote'].quantity++; money-=50;", "Restores status to unpoisoned.");
	thashop.execute(xbo, 50+ybo, 320-xbo*2, 240-ybo*2-50);
}


function mcmenu()
{
	var thashop = new CMenu("What's your order?");
	thashop.addItem("Leafer Letus", "items['lletus'].quantity++; money-=50;", "Vegitarians: It's plant AND animal.");
	thashop.addItem("Chicken Lip Legs", "items['cll'].quantity++; money-=50;", "Don't ask.");
	thashop.addItem("Chicken Lip Nuggets", "items['cln'].quantity++; money-=50;", "Ground hardcore.");
	thashop.addItem("Pug Soup", "items['psoup'].quantity++; money-=50;", "Chunky?");
	thashop.addItem("Rhodox", "items['rhodox'].quantity++; money-=50;", "I think it's a burger..");
	thashop.addItem("Rhodox w/ Cheese", "items['rhodoxc'].quantity++; money-=75;", "Cheesy.");
	thashop.addItem("Were-Rat Kabob", "items['bob'].quantity++; money-=55;", "New!");
	thashop.addItem("Behemoth Burger", "items['bburger'].quantity++; money-=100;", "For big fellas.");
	thashop.addItem("Peppered Peepers", "items['pps'].quantity++; money-=75;", "....EW!");
	thashop.addItem("Rhobite Stew", "items['rstew'].quantity++; money-=75;", "EAT!");
	thashop.addItem("Mashed Muu", "items['mmuu'].quantity++; money-=75;", "All this food is making me sick.");
	thashop.addItem("Mind Candy", "items['mcandy'].quantity++; money-=75;", "Hmm.");
	thashop.addItem("Gold Bear Crunch Bar", "items['gbcr'].quantity++; money-=75;", "Yeuh.");
	thashop.addItem("Fries of FlameEater", "items['fee'].quantity++; money-=75;", "Probably spicey.");
	thashop.addItem("Hidonites in a Box", "items['hbox'].quantity++; money-=75;", "Awaiting FDA approval.");
	thashop.addItem("Poppers Corn", "items['pcorn'].quantity++; money-=75;", "Who's paying for this?");
	thashop.addItem("Cactrot Cola", "items['cc'].quantity++; money-=75;", "A cold one.");
	thashop.addItem("Value McMeal", "items['vmeal'].quantity++; money-=50;", "Quick and cheap eating.");
	thashop.execute(xbo, 50+ybo, 320-xbo*2, 240-ybo*2-50);
}

function mcmenu_mcgraw()
{
	var fastfood = new shopmenu();
}


function choosepartymenu()
{
	ApplyColorMask(Black);
	window.drawWindow(xbo, ybo, 320-xbo*2, 240-ybo*2);
	window2.drawWindow(xbor, 13, 320-xbor*2, 15);
	window2.drawWindow(xbor*2-7, 50, 110, 150);
	alphagrad.blit(0,0);
	font.drawText(100, 15, "Throw a party!");
	font.drawText(175, 65, "1st");
	font.drawText(175, 105, "2nd");
	font.drawText(175, 145, "3rd");
	font.drawText(175, 185, "4th");

	var blackground = GrabImage(0,0,320,240);
	var partyhard = true;
	var YP=0;
	var displimit = 12;
	var toppo = 0;
	var tardlist = [" -END-"];
 	for (var d=0; d<charlist.length; d++)
		tardlist[d+1] = charlist[d];
	var tempparty = [];
	var four = 0;
	var waiter = 250;
	var starter = GetTime();
	var charimgs = [];
	var loadchar = false, charloadded = false; showchar = false;
	
	while (partyhard)
	{
		blackground.blit(0,0);
		for (var b=0; b<displimit; b++)
			if (b+toppo < tardlist.length) font.drawText(30, 55+b*12, tardlist[b+toppo]);
		pointer.blit(10, 55+(YP-toppo)*12);

		loadchar = ((YP > 0) && (GetTime() > starter + waiter) && !charloadded && four<4);	//wait to stop scrolling
		if (loadchar)
		{
			var damnspr = LoadSpriteset(charstats[charlist[YP-1]].rss);
			for (var r=0; r<damnspr.directions.length; r++)
				if (damnspr.directions[r].name == "south")
					charimgs[four] = damnspr.images[damnspr.directions[r].frames[0].index];
			charloadded = true;
			showchar = true;
		}
		
		if (showchar)
			charimgs[four].blit(210, 60+four*40);
			
		for (var g=0; g<four; g++)
			charimgs[g].blit(210, 60+g*40);
		
		FlipScreen();

		if (AreKeysLeft())
		{
		switch (GetKey())
		{
			case key_talk:
			{
				if (YP==0) if (four==0) return; else partyhard = false;
				if (four<4 && showchar)
				{
					tempparty[four] = tardlist[YP];
					four++;
					showchar = false;
					charloadded = false;
					starter = GetTime();
				}
				break;
			}
			case KEY_DOWN:
			{
				if (YP != tardlist.length-1)
				{
					YP++;
					if (YP>=displimit) toppo++;
					showchar = false;
					charloadded = false;
					starter = GetTime();
				}
				break;
			}
			case KEY_UP:
			{
				if (YP != 0)
				{
					YP--;
					if (YP<toppo) toppo--;
					showchar = false;
					charloadded = false;
					starter = GetTime();
				}
				break;
			}
			case key_cancel:
			{
				if (four!=0) partyhard = false;
			}
		}
		}
	}
	//change the party
	party = tempparty;
	//change the PC anyway
	var xy=GetPersonX(thePC.name),yx=GetPersonY(thePC.name);
	DestroyPerson(thePC.name);
	thePC = new retard(party[0], charstats[party[0]].rss, false);
	SetPersonX(thePC.name, xy);
	SetPersonY(thePC.name, yx);
	people = GetPersonList();
	AttachInput(thePC.name);
	AttachCamera(thePC.name);

}

function notlocked(pad)
{
	//unless a certain event passed..
	if (pad=="shardfactory") return false;
	
	if (thempa=="Albrook.rmp" && (IsLayerVisible(4) || eventBox['scene1'].inprog))	//nighttime or chasetime
	{
		if (pad=="jail" || pad=="court" || pad=="toys" || pad=="mteks" || pad=="mcm" || pad=="trishop" ||
			pad=="towers" || pad=="ares1" || pad=="ares4" || pad=="ares5" || pad=="gimms" || pad=="oldshouse" ||
			pad=="ares6")	return false;
		else return true;
	}
	else return true;
	
}

function getmapbgm(pad)
{
	if (pad=="Albrook.rmp")
	{
		if (eventBox['furniture_mission'].inprog) return "music/crickets_loop_004.wav";
		else return "music/Albrook.it";
	}
	if (pad=="Aresidence2.rmp")
		if (eventBox['furniture_mission'].inprog)
			return "music/crickets_loop_004_low.wav";
	if (pad=="Aresidence3.rmp")
		if (eventBox['furniture_mission'].inprog)
			return "music/crickets_loop_004_low.wav";
	if (pad=="Mayorshouse.rmp")
		if (eventBox['furniture_mission'].inprog)
			return "music/crickets_loop_004_low.wav";
	if (pad=="Auhouse1.rmp")
		if (eventBox['furniture_mission'].inprog)
			return "music/crickets_loop_004.wav";
	if (pad=="Auhouse2.rmp")
		if (eventBox['furniture_mission'].inprog)
			return "music/crickets_loop_004.wav";
	if (pad=="Auhouse3.rmp")
		if (eventBox['furniture_mission'].inprog)
			return "music/crickets_loop_004.wav";
	if (pad=="Auhouse4.rmp")
		if (eventBox['furniture_mission'].inprog)
			return "music/crickets_loop_004.wav";
	if (pad=="Aresidence8.rmp") return "";
	if (pad=="Aforest1.rmp") return "music/MysticForest.it";
	if (pad=="Aforest5.rmp") return "music/MysticForest.it";
	if (pad=="JonesRd.rmp") return "";
	if (pad=="JonesHouse.rmp") return "music/Maximum_Senility.it";
	if (pad=="Worldmap.rmp") return "music/WorldMap.it";
	if (pad=="Mcmoogles.rmp") return "music/RhodoxWithCheese.it";
	if (pad=="Tzen.rmp") return "";//"music/Tzen.it";
	if (pad=="Tzenrichyrich.rmp") return "music/Fitzgerald.it";
	if (pad=="Asewer1.rmp") return "music/sewers.it";

	return thebgmname;
}

function getmapbgmfadeIN(pad)
{
	//if (pad=="Albrook.rmp") return true;
	return false;
}

function NightBrook()
{
//	if (IsLayerVisible(4)) return;
	SetLayerVisible(4,true);
	//turn off music
	//bgmswitch('Crickets.ogg');
	
	//close mcm
	SetTile(8,50,1, 427); SetTile(8, 49, 1, 396); CreatePerson("mcmlock", "blank.rss", true); 
	SetPersonX("mcmlock", 8*16+7); SetPersonY("mcmlock", 50*16+7); SetPersonLayer("mcmlock", 1);
	
	//delete almost everyone
	DestroyPerson('hungryjack');
	DestroyPerson('domaentry');
	DestroyPerson('floresthump');
	DestroyPerson('kid2');
	DestroyPerson('trashkid');
	DestroyPerson('crackle');
	DestroyPerson('magisell');
	DestroyPerson('snatchee');
	DestroyPerson('mcm');
	DestroyPerson('narshehungry');
	DestroyPerson('dudestinks');
	DestroyPerson('shoper'); 
	DestroyPerson('infoguy');
	DestroyPerson('onpatrol');
	DestroyPerson('annoyinggirl'); 
	DestroyPerson('roofus');
	DestroyPerson('boo'); 
	DestroyPerson('disgruntledworker'); 
	DestroyPerson('postman');
	DestroyPerson('chocodelivery');
	DestroyPerson('birdturd');
	if (!eventBox['prechase'].happened)
	{
	DestroyPerson('pilot');
	DestroyPerson('spect3');
	DestroyPerson('spect2');
	DestroyPerson('spect1');
	}
	if (eventBox['furniture_mission'].inprog)	//he would spotya hauling
	DestroyPerson('flashlightjones');
	DestroyPerson('register');
	// he got ousted hooah! DestroyPerson('alleywayjones');
	DestroyPerson('donate');
	
	SetPersonScript('loader', 3, "talkjunk('MAN: I can NOT BELIEVE I am working\\ndouble shifts! I want to KILL my boss!');");
	//create bums and drunks
	people = GetPersonList();
}

function DayBrook()
{
	if (IsLayerVisible(4)) SetLayerVisible(4, false);
	
	DestroyPerson('aguard1');
	if (!eventBox['kefka_split'].inprog)
	{
	DestroyPerson('polit');
	DestroyPerson('richman');
	}
	DestroyPerson('flashlightjones');
	DestroyPerson('meating');
	if (!eventBox['prechase'].inprog)
	{
	DestroyPerson('bob');
	DestroyPerson('billy');
	DestroyPerson('blackmark');
	}
	DestroyPerson('fire');
	DestroyPerson('lonewolf');
	DestroyPerson('trafficop');
	DestroyPerson('sammich');
}

//IDLES!!

function idlefunK(it)
{
	if (it==0)
	{
		if (idle) SetPersonDirection('Kefka', 'south');
		SetDelayScript(50,   "if (idle) SetPersonDirection('Kefka', 'lookwest');");
		SetDelayScript(100, "if (idle) SetPersonDirection('Kefka', 'south');");
		SetDelayScript(150, "if (idle) SetPersonDirection('Kefka', 'lookeast');");
		SetDelayScript(200, "if (idle){SetPersonDirection('Kefka', 'south'); idletime=GetTime();} idle=false; checkidle=true;");
	}

	else if (it==1)
	{
		if (idle) SetPersonDirection('Kefka', 'south');
		SetDelayScript(50,   "if (idle) SetPersonDirection('Kefka', 'scratch'); SetPersonFrame('Kefka', 1);");
		SetDelayScript(75, "if (idle) SetPersonFrame('Kefka', 0);");
		SetDelayScript(120, "if (idle){SetPersonDirection('Kefka', 'south'); SetPersonFrame('Kefka', 0); idletime=GetTime();} idle=false; checkidle=true;");
	}
	
	else if (it==2)
	{
		if (idle) SetPersonDirection('Kefka', 'south');
		SetDelayScript(50,   "if (idle) SetPersonDirection('Kefka', 'nono');");
		SetDelayScript(70, "if (idle) SetPersonFrame('Kefka', 1);");
		SetDelayScript(90, "if (idle) SetPersonFrame('Kefka', 0);");
		SetDelayScript(110, "if (idle) SetPersonFrame('Kefka', 1);");
		SetDelayScript(130, "if (idle) SetPersonFrame('Kefka', 0);");
		SetDelayScript(150, "if (idle) SetPersonFrame('Kefka', 1);");
		SetDelayScript(170, "if (idle){SetPersonDirection('Kefka', 'south'); SetPersonFrame('Kefka', 0); idletime=GetTime();} idle=false; checkidle=true;");
	}
	
	else if (it==3)
	{
		if (idle) SetPersonDirection('Kefka', 'south');
		SetDelayScript(50,   "if (idle) SetPersonDirection('Kefka', 'crouch');");
		SetDelayScript(100, "if (idle) SetPersonDirection('Kefka', 'owch');");
		SetDelayScript(275, "if (idle) SetPersonDirection('Kefka', 'crouch');");
		SetDelayScript(300, "if (idle){SetPersonDirection('Kefka', 'south'); SetPersonFrame('Kefka', 0); idletime=GetTime();} checkidle=true;");
	}
	
	else if (it==4)
	{
		if (idle) SetPersonDirection('Kefka', 'south');
		SetDelayScript(50,   "if (idle) SetPersonDirection('Kefka', 'blink');");
		SetDelayScript(70,   "if (idle) SetPersonDirection('Kefka', 'south');");
		SetDelayScript(90,   "if (idle) SetPersonDirection('Kefka', 'blink');");
		SetDelayScript(110, "if (idle) SetPersonDirection('Kefka', 'south');");
		SetDelayScript(130, "if (idle) SetPersonDirection('Kefka', 'blink');");
		SetDelayScript(150, "if (idle){SetPersonDirection('Kefka', 'south'); SetPersonFrame('Kefka', 0); idletime=GetTime();} idle=false; checkidle=true;");
	}

	else if (it==5)
	{
		if (idle) SetPersonDirection('Kefka', 'south');
		SetDelayScript(50,   "if (idle) SetPersonDirection('Kefka', 'anger');");
		SetDelayScript(70,   "if (idle) SetPersonDirection('Kefka', 'stickup');");
		SetDelayScript(90,   "if (idle) SetPersonDirection('Kefka', 'anger');");
		SetDelayScript(110, "if (idle) SetPersonDirection('Kefka', 'stickup');");
		SetDelayScript(130, "if (idle) SetPersonDirection('Kefka', 'anger');");
		SetDelayScript(150, "if (idle) SetPersonDirection('Kefka', 'stickup');");
		SetDelayScript(170, "if (idle) SetPersonDirection('Kefka', 'anger');");
		SetDelayScript(190, "if (idle){SetPersonDirection('Kefka', 'south'); SetPersonFrame('Kefka', 0); idletime=GetTime();} idle=false; checkidle=true;");
	}
	
	else if (it==6)
	{
		if (idle) SetPersonDirection('Kefka', 'south');
		SetDelayScript(50,   "if (idle) SetPersonDirection('Kefka', 'looksouth');");
		SetDelayScript(225, "if (idle){SetPersonDirection('Kefka', 'south'); SetPersonFrame('Kefka', 0); idletime=GetTime();} checkidle=true;");
	}
	
	else if (it==7)
	{
		if (idle) SetPersonDirection('Kefka', 'south');
		SetDelayScript(50,   "if (idle) SetPersonDirection('Kefka', 'shocked');");
		SetDelayScript(100, "if (idle){SetPersonDirection('Kefka', 'south'); SetPersonFrame('Kefka', 0); idletime=GetTime();} checkidle=true;");
	}
	else
	{
		//uh oh!
	}
}

function idlefunB(it)
{
	if (it==0)
	{
		if (idle) SetPersonDirection(thePC.name, 'south');
		SetDelayScript(50, "if (idle) SetPersonDirection(thePC.name, 'ldownwest');");
		SetDelayScript(100, "if (idle) SetPersonDirection(thePC.name, 'crouch');");
		SetDelayScript(150, "if (idle) SetPersonDirection(thePC.name, 'down1');");
		SetDelayScript(215, "if (idle) SetPersonDirection(thePC.name, 'crouch');");
		SetDelayScript(225, "if (idle) SetPersonDirection(thePC.name, 'south');");
		SetDelayScript(250, "if (idle) SetPersonDirection(thePC.name, 'laugh');");
		SetDelayScript(255, "if (idle) SetPersonFrame(thePC.name, 1);");
		SetDelayScript(260, "if (idle) SetPersonFrame(thePC.name, 0);");
		SetDelayScript(265, "if (idle) SetPersonFrame(thePC.name, 1);");
		SetDelayScript(270, "if (idle) SetPersonFrame(thePC.name, 0);");
		SetDelayScript(275, "if (idle) SetPersonFrame(thePC.name, 1);");
		SetDelayScript(290, "if (idle){SetPersonDirection(thePC.name, 'south'); SetPersonFrame(thePC.name,0); idletime=GetTime();} checkidle=true;");
	}
	else if (it==1)
	{
		if (idle) SetPersonDirection(thePC.name, 'south');
		SetDelayScript(50, "if (idle) SetPersonDirection(thePC.name, 'no');");
		SetDelayScript(53, "if (idle) SetPersonFrame(thePC.name, 1);");
		SetDelayScript(56, "if (idle) SetPersonFrame(thePC.name, 2);");
		SetDelayScript(59, "if (idle) SetPersonFrame(thePC.name, 3);");
		SetDelayScript(62, "if (idle) SetPersonFrame(thePC.name, 0);");
		SetDelayScript(65, "if (idle) SetPersonFrame(thePC.name, 1);");
		SetDelayScript(68, "if (idle) SetPersonFrame(thePC.name, 2);");
		SetDelayScript(71, "if (idle) SetPersonFrame(thePC.name, 3);");
		SetDelayScript(74, "if (idle) SetPersonFrame(thePC.name, 0);");
		SetDelayScript(77, "if (idle) SetPersonFrame(thePC.name, 1);");
		SetDelayScript(80, "if (idle) SetPersonFrame(thePC.name, 2);");
		SetDelayScript(83, "if (idle) SetPersonFrame(thePC.name, 3);");
		SetDelayScript(86, "if (idle){SetPersonDirection(thePC.name,'south'); SetPersonFrame(thePC.name,0); idletime=GetTime();} checkidle=true;");
	}
}


//	ILE DETONATION
function InsaneLaughEngine()
{
	var nerds = GetPersonList();
	for (var b=0; b<nerds.length; b++)
		if (nerds[b] != thePC.name)
		if (Math.abs(GetPersonX(nerds[b]) - GetPersonX(thePC.name)) < 160 && Math.abs(GetPersonY(nerds[b]) - GetPersonY(thePC.name)) < 120)
			if (eval(nerds[b]).ile) eval(nerds[b]).ile.play();
}


//	ILE REACTIONS

function AlbrookILEs()
{
	rts = 0;
	itr = 0;
	
	hungryjack.ile = new miniscene()
	{
		with (hungryjack)
		{
			ile.clean = true;
			ile.play = function()
			{
				if (isinsubq(hungryjack.ile)) return;
				ile.ateq("");
				ile.ateq("hungryjack.ile.inprog=true;");
				ile.ateq("var sx=GetPersonX('hungryjack'); var sy=GetPersonY('hungryjack'); DestroyPerson('hungryjack'); CreatePerson('hungrycho', 'Chocobo.rss', true); hungrycho= new npcrap('hungrycho'); SetPersonX('hungrycho', sx); SetPersonY('hungrycho', sy); SetPersonDirection('hungrycho','wark'); CreatePerson('hungryduh', 'Albrookguard.rss', true); hungryduh = new npcrap('hungryduh'); SetPersonX('hungryduh',sx); SetPersonY('hungryduh', sy-8); SetPersonDirection('hungryduh', 'buck'); SetPersonLayer('hungryduh', 2); people=GetPersonList();");
				ile.ateq("IgnorePersonObstructions('hungrycho', true); IgnorePersonObstructions('hungryduh',true);");
				for (var g=0; g<8; g++)
				ile.ateq("SetPersonY('hungrycho', GetPersonY('hungrycho')-2); SetPersonY('hungryduh', GetPersonY('hungryduh')-2); SetPersonX('hungryduh', GetPersonX('hungryduh')+1);");
				ile.ateq("SetPersonDirection('hungryduh', 'shock'); SetPersonLayer('hungryduh', 1);");
				for (var g=0; g<8; g++)
				ile.ateq("SetPersonY('hungrycho', GetPersonY('hungrycho')+2); SetPersonY('hungryduh', GetPersonY('hungryduh')-1); SetPersonX('hungryduh', GetPersonX('hungryduh')+1);");
				for (var g=0; g<10; g++)
				ile.ateq("SetPersonY('hungryduh', GetPersonY('hungryduh')+2); SetPersonX('hungryduh', GetPersonX('hungryduh')+1);");
				for (var g=0; g<5; g++)
				ile.ateq("SetPersonY('hungryduh', GetPersonY('hungryduh')+4);");
				ile.ateq("SetPersonDirection('hungryduh', 'wrecked');");
				ile.ateq("SetPersonSpeed('hungrycho', 2.5);");
				ile.ateq("var CXD = (GetPersonX('hungrycho') - (18*16+7)); if (CXD>0){ QueuePersonCommand('hungrycho', pcfl, 0); for (var c=0; c<Math.floor(CXD/2.5); c++) QueuePersonCommand('hungrycho', pcml, 0); }");
				ile.ateq("QueuePersonCommand('hungrycho', pcfu, 0); for (var c=0; c<(GetPersonY('hungrycho')-(42*16+7))/2.5; c++) QueuePersonCommand('hungrycho', pcmu, 0);");
				ile.ateq("QueuePersonScript('hungrycho', 'hungryjack.ile.proceed=true;', false); hungryjack.ile.proceed=false;");
				ile.ateq("QueuePersonCommand('hungrycho', pcfl, 0); for (var c=0; c<(GetPersonX('hungrycho')-(2*16+7))/2.5; c++) QueuePersonCommand('hungrycho', pcml,0);");
				ile.ateq("QueuePersonCommand('hungrycho', pcfu, 0); for (var c=0; c<4*16/2.5; c++) QueuePersonCommand('hungrycho', pcmu, 0);");
				ile.ateq("QueuePersonScript('hungrycho', 'hungryjack.ile.proceed=true;', false); hungryjack.ile.proceed=false;");
				ile.ateq("DestroyPerson('hungrycho'); people=GetPersonList();");
				
				ile.ateq("hungryjack.ile.inprog=false; remove(hungryjack.ile);");
				ile.proceed=true;
				ile.inprog = true;
				subevq.push(hungryjack.ile);
			}
		}
	}
	
	
	mcm.ile = new miniscene()
	{
		with (mcm)
		{
			if (isinsubq(mcm.ile)) return;
			ile.clean = true;
			ile.play = function()
			{
				ile.ateq("");
				ile.ateq("mcm.ile.inprog=true;");
				ile.ateq("SetPersonFrame('mcm', 0); mcm.dirs = []; SetPersonScript('mcm',4,';'); IgnorePersonObstructions('mcm', true); IgnoreTileObstructions('mcm', true);");
				ile.ateq("mcm.ile.proceed=false; SetDelayScript(20, 'mcm.ile.proceed=true;');");
				ile.ateq("SetPersonDirection('mcm', 'shock'); SetPersonSpeed('mcm', 2);");
				for (var i=0; i<8; i++)
				ile.ateq("SetPersonY('mcm', GetPersonY('mcm')-2);");
				ateq("");
				for (var i=0; i<8; i++)
				ile.ateq("SetPersonY('mcm', GetPersonY('mcm')+2);");
				ile.ateq("mcm.ile.proceed=false; SetDelayScript(16, 'mcm.ile.proceed=true;');");
				ile.ateq("SetPersonDirection('mcm', ((8*16+7 - GetPersonX('mcm'))>0) ? 'east' : 'west');");
				ile.ateq("var MXD = (8*16+7 - GetPersonX('mcm')); for (var i=0; i<Math.abs(MXD)/2; i++) QueuePersonCommand('mcm', (MXD>0) ? pcmr : pcml, false);");
				ile.ateq("QueuePersonCommand('mcm', pcfu, false);");
				ile.ateq("for (var i=0; i<24; i++) QueuePersonCommand('mcm', pcmu, false);");
				ile.ateq("mcm.ile.proceed=false; QueuePersonScript('mcm', 'mcm.ile.proceed=true;', false);");
				ile.ateq("DestroyPerson('mcm'); people=GetPersonList();");
				ile.ateq("people = GetPersonList();");
				ile.ateq("mcm.ile.inprog=false; remove(mcm.ile);");
				
				ile.proceed=true;
				ile.inprog=true;
				subevq.push(mcm.ile);
			}
		}
	}

	oldfogey.ile = new miniscene()
	{
		with (oldfogey)
		{
			ile.clean = true;
			ile.play = function()
			{
				if (isinsubq(oldfogey.ile) || oldfogey.ile.happened) return;
				ile.ateq("");
				for (var b=0; b<40; b++)
				{
					if (b<15)
					ile.ateq("SetPersonX('oldfogey', GetPersonX('oldfogey')+1); SetPersonY('oldfogey', GetPersonY('oldfogey') - 2); SetPersonAngle('oldfogey', GetPersonAngle('oldfogey') + rad(5));");
					else if (b<20)
					ile.ateq("SetPersonX('oldfogey', GetPersonX('oldfogey')+1); SetPersonY('oldfogey', GetPersonY('oldfogey') - 1); SetPersonAngle('oldfogey', GetPersonAngle('oldfogey') + rad(5));");
					else if (b<25)
					ile.ateq("SetPersonX('oldfogey', GetPersonX('oldfogey')+1); SetPersonAngle('oldfogey', GetPersonAngle('oldfogey') + rad(5));");
					else if (b<30)
					ile.ateq("SetPersonX('oldfogey', GetPersonX('oldfogey')+1); SetPersonY('oldfogey', GetPersonY('oldfogey') + 1); SetPersonAngle('oldfogey', GetPersonAngle('oldfogey') + rad(5));");
					else if (b<40)
					ile.ateq("SetPersonX('oldfogey', GetPersonX('oldfogey')+1); SetPersonY('oldfogey', GetPersonY('oldfogey') + 2); SetPersonAngle('oldfogey', GetPersonAngle('oldfogey') + rad(5));");
				}
				for (var c=0; c<30; c++)
				{
					if (c<20)
					ile.ateq("SetPersonX('oldfogey', GetPersonX('oldfogey')+1); SetPersonY('oldfogey', GetPersonY('oldfogey') + 3); SetPersonAngle('oldfogey', GetPersonAngle('oldfogey') + rad(5));");
					else
					ile.ateq("SetPersonX('oldfogey', GetPersonX('oldfogey')+1); SetPersonY('oldfogey', GetPersonY('oldfogey') + 4); SetPersonAngle('oldfogey', GetPersonAngle('oldfogey') + rad(5));");
				}
				ile.ateq("SetPersonAngle('oldfogey', 0); SetPersonDirection('oldfogey', 'swimmin');");
				ile.ateq("SetPersonScript('oldfogey', 4, 'if (oldfogey.step > oldfogey.dirs.length) oldfogey.step=0; walkgay(oldfogey, oldfogey.dirs[oldfogey.step]);');");
				ile.ateq("oldfogey.dirs = ['SetPersonFrame(oldfogey.name, 0);', ';', ';', 'SetPersonFrame(oldfogey.name, 1);', ';', ';'];");
				ile.ateq("oldfogey.ile.proceed=false; SetDelayScript(40, 'oldfogey.ile.proceed=true;');");
				ile.ateq("SetPersonLayer('oldfogey', 1);");
				for (var d=0; d<50; d++)
				ile.ateq("SetPersonY('oldfogey', GetPersonY('oldfogey')+1);");
				
				ile.ateq("oldfogey.ile.happened = true; remove(oldfogey.ile);");
				
				ile.inprog = true;
				ile.proceed = true;
				subevq.push(oldfogey.ile);
			}
		}
	}

}

function McmooglesILEs()
{

	impresso.ile = new miniscene()
	{
		with (impresso)
		{
			ile.clean = true;
			ile.play = function()
			{
				if  (isinsubq(impresso.ile)) return;
				ile.ateq("");
				ile.ateq("impresso.ile.inprog=true;");
				ile.ateq("SetPersonDirection('impresso', 'choke');");
				ile.ateq("impresso.step=0; ClearPersonCommands(impresso.name);");
				ile.ateq("impresso.dirs = ['SetPersonFrame(impresso.name, 0);', ';', 'SetPersonFrame(impresso.name, 1);', ';', 'SetPersonFrame(impresso.name, 2);', ';', 'SetPersonFrame(impresso.name, 3);', ';'];");
				ile.ateq("impresso.ile.proceed=false; SetDelayScript(500, 'impresso.ile.proceed=true;');");
				ile.ateq("SetPersonDirection('impresso', 'sit');");
				ile.ateq("impresso.dirs = ['w','w','w',\"SetPersonFrame('impresso', 1);\",'w',\"SetPersonFrame('impresso', 2);\",'w', \"SetPersonFrame('impresso', 3);\",'w', \"SetPersonFrame('impresso', 4);\",'w'];");

				ile.ateq("impresso.ile.inprog=false; remove(impresso.ile);");

				ile.proceed=true;
				ile.inprog=true;
				subevq.push(impresso.ile);
			}
		}
	}
	
	guarda.ile = new miniscene()
	{
		with (guarda)
		{
			ile.clean = true;
			ile.play = function()
			{
				if (isinsubq(guarda.ile)) return;
				var path ="";
				for (var c=0; c<9; c++)			
					path += "'fr','r','r','fl','l','l',";
					path += "'fr','r','r', 'SetPersonSpeed(guarda.name, 1);', 'fl','l','l','l','l','fu', 'guarda.ile.proceed=true;'";
				ile.ateq("");
				ile.ateq("guarda.ile.inprog = true;");
				ile.ateq("SetPersonDirection('guarda', 'shock'); SetPersonY('guarda', GetPersonY('guarda')-8);");
				ile.ateq("guarda.ile.proceed=false; SetDelayScript(15, 'guarda.ile.proceed=true;');");
				ile.ateq("IgnoreTileObstructions('guarda', true); IgnorePersonObstructions('guarda', true); SetPersonSpeed('guarda', 2);");
				ile.ateq("guarda.step=0; ClearPersonCommands('guarda'); SetPersonScript('guarda', 4, 'walkgay(guarda, guarda.dirs[guarda.step]);');");
				ile.ateq("SetPersonDirection('guarda', 'south'); SetPersonY('guarda', GetPersonY('guarda')+8);");
				ile.ateq("for (var v=0; v<8; v++) QueuePersonCommand('guarda', pcmd, false);");
				ile.ateq("guarda.dirs = [" + path + "]; guarda.ile.proceed=false;");
				ile.ateq("for (var v=0; v<20; v++) QueuePersonCommand('guarda', pcmu, false); QueuePersonScript(guarda.name, 'guarda.ile.proceed=true;',false); guarda.ile.proceed=false;");			
				ile.ateq("SetPersonDirection('guarda', 'east'); SetPersonFrame('guarda', 0);");
				ile.ateq("guarda.dirs = [];");
			
				ile.ateq("guarda.ile.inprog=false; remove(guarda.ile);");
				
				ile.proceed=true;
				ile.inprog=true;
				subevq.push(guarda.ile);
			}
		}
	}
}



var wm_tile_indeces = [[]];
var h_scales = [17, 16, 15, 15, 14, 14, 13, 12, 12, 11, 10, 10,   9,   8,  8,  7,   6,   6,   5,  4,  3, 2, 2, 1, 1];
var w_scales = [17, 16, 16, 15, 15, 15, 14, 14, 14, 13, 13, 13, 12, 12, 12, 11, 11, 11, 10, 10, 9, 9, 9, 8, 8];

function worldmapfuckdation()
{
	for (var h=15; h>0; h--)
		for (var w=0; w<20; w++)
			wm_tile_indeces[h[w]] = GetTile( Math.floor( (GetPersonX(thePC.name)-7-160)/16)+w , Math.floor((GetPersonY(thePC.name)-7)/16-120)+h, 1);
			
	for (var h=0; h<15; h++)
	{
		for (var w=0; w<20; w++)
		{
			GetTileImage(wm_tile_indeces[h[w]]).transformBlit(
					w_scales[h]*w,		240-h_scales[h]*w,						w_scales[h]*(w+1),		240-h_scales[h]*w,
					w_scales[h]*(w+1),	240-h_scales[h]*(w-1),					w_scales[h]*w,			240-h_scales[h]*(w-1)
				);
		}
	}

}

/*
8x1 
8x1 
9x2 
9x2 
9x3 
10x4 
10x5 
11x6 
11x6 
11x7 
12x8 
12x8 
12x9 
13x10 
13x10 
13x11 
14x12 
14x12 
14x13 
15x14 
15x14 
15x15 	
16x15 	48
16x16		33
17x17		
*/



////////////////

// SEWER SHIT

//////////////////




function blueswitch()
{
	if (!switches[001])
	{
	   switches[001] = 1;		//ON, turns off sewage at 29,3
	   SetTile(28, 19, 1, 97);							//switch down
	   SetTile(35,9,1, 134); SetTile(35,10,1, 135);	//other switch up
	   getter("Throw-2.ogg").play(false);	
	   
	   //sewege OFF at 29,3
	   SetTile(29,4, 3, 0); SetTile(29,5, 3, 0); SetTile(29,6, 3, 0); SetTile(29,7, 3, 0); SetTile(29,8, 3, 0); SetTile(29,9, 3, 0); SetTile(29,10, 3, 0); SetTile(29,11, 3, 0);
	   SetTile(30,4, 3, 0); SetTile(30,5, 3, 0); SetTile(30,6, 3, 0); SetTile(30,7, 3, 0); SetTile(30,8, 3, 0); SetTile(30,9, 3, 0); SetTile(30,10, 3, 0); SetTile(30,11, 3, 0);
	   //grate
	   SetTile(29,11, 1, 101); SetTile(30,11, 1, 101); SetTile(29,12, 1, 101); SetTile(30,12, 1, 101); 
	   //sewage ON at 40,30
	   SetTile(40,31, 3, 172); SetTile(40,32, 3, 172); SetTile(40,33, 3, 172); SetTile(40,34, 3, 172); SetTile(40,35, 3, 172); SetTile(40,36, 3, 172);SetTile(40,37, 3, 166);
	   SetTile(41,31, 3, 188); SetTile(41,32, 3, 188); SetTile(41,33, 3, 188); SetTile(41,34, 3, 188); SetTile(41,35, 3, 188); SetTile(41,36, 3, 188); SetTile(41,37, 3, 169);
	   //grate
	   SetTile(40,37,1, 205); SetTile(40,37,1, 205); SetTile(40,37,1, 205);  SetTile(40,37,1, 205); 
	  
	}
	else
	{
	  switches[001] = 0;
	  
	   SetTile(28, 19, 1, 96);								//switch up
	   SetTile(35,9,1, 136); SetTile(35,10,1, 137);	   //other switch down
	   getter("Throw-2.ogg").play(false);	
	   	   
	   //sewage ON at 29,3
	   SetTile(29,4, 3, 172); SetTile(29,5, 3, 172); SetTile(29,6, 3, 172); SetTile(29,7, 3, 172); SetTile(29,8, 3, 172); SetTile(29,9, 3, 172); SetTile(29,10, 3, 172); SetTile(29,11, 3, 166);
	   SetTile(30,4, 3, 188); SetTile(30,5, 3, 188); SetTile(30,6, 3, 188); SetTile(30,7, 3, 188); SetTile(30,8, 3, 188); SetTile(30,9, 3, 188); SetTile(30,10, 3, 188); SetTile(30,11, 3, 169);
	   //grate
	   SetTile(20,11,1, 205);  SetTile(30,11, 1, 205); SetTile(29,12, 1, 205); SetTile(30,12, 1, 205); 
	   
	   //sewage OFF at 40,30
	   SetTile(40,31, 3, 0); SetTile(40,32, 3, 0); SetTile(40,33, 3, 0); SetTile(40,34, 3, 0); SetTile(40,35, 3, 0); SetTile(40,36, 3, 0); SetTile(40,37, 3, 0);
	   SetTile(41,31, 3, 0); SetTile(41,32, 3, 0); SetTile(41,33, 3, 0); SetTile(41,34, 3, 0); SetTile(41,35, 3, 0); SetTile(41,36, 3, 0); SetTile(41,37, 3, 0);
	   //grate
	   SetTile(40,37,1, 101); SetTile(40,37,1, 101); SetTile(40,37,1, 101);  SetTile(40,37,1, 101); 	   
	}
}


function redswitch()
{
	if (!switches[002])
	{
	   switches[002] = 1;	

	   SetTile(32, 38, 1, 138);	//switch up
	   SetTile(17,31,1, 139);  //other switch down

	   getter("Throw-2.ogg").play(false);	
	   
	   //sewege OFF at 21,31
	   SetTile(21,31, 3, 0); SetTile(21,32, 3, 0); SetTile(21,33, 3, 0); SetTile(21,34, 3, 0); SetTile(21,35, 3, 0); SetTile(21,36, 3, 0); SetTile(21,37, 3, 0); SetTile(21,38, 3, 0); SetTile(21,39,3,0);
	   SetTile(22,31, 3, 0); SetTile(22,32, 3, 0); SetTile(22,33, 3, 0); SetTile(22,34, 3, 0); SetTile(22,35, 3, 0); SetTile(22,36, 3, 0); SetTile(22,37, 3, 0); SetTile(22,38, 3, 0); SetTile(22,39,3,0);
	   //grate
	   SetTile(21,38, 1, 101); SetTile(21,39, 1, 101); SetTile(22,38, 1, 101); SetTile(22,39, 1, 101); 
	   //sewage ON at 35,31
	   SetTile(35,31, 3, 172); SetTile(35,32, 3, 172); SetTile(35,33, 3, 172); SetTile(35,34, 3, 172); SetTile(35,35, 3, 172); SetTile(35,36, 3, 172);SetTile(35,37, 3, 172); SetTile(35,38,3,172); SetTile(35,39,3,166);
	   SetTile(36,31, 3, 188); SetTile(36,32, 3, 188); SetTile(36,33, 3, 188); SetTile(36,34, 3, 188); SetTile(36,35, 3, 188); SetTile(36,36, 3, 188); SetTile(36,37, 3, 188); SetTile(36,38,3,188); SetTile(36,39,3,169);
	   //grate
	   SetTile(35,38,1, 205); SetTile(35,39,1, 205); SetTile(36,38,1, 205);  SetTile(36,39,1, 205); 
	  
	}
	else
	{
	  switches[002] = 0;
	   SetTile(32, 38, 1, 139);	//switch down
	   SetTile(17,31,1, 138);  //other switch up
	  
	   getter("Throw-2.ogg").play(false);	
	   
	   //sewege ON at 21,31
	   SetTile(21,31, 3,172); SetTile(21,32, 3,172); SetTile(21,33, 3,172); SetTile(21,34, 3,172); SetTile(21,35, 3,172); SetTile(21,36, 3,172); SetTile(21,37, 3, 172); SetTile(21,38, 3, 172); SetTile(21,39,3,166);
	   SetTile(22,31, 3,188); SetTile(22,32, 3,188); SetTile(22,33, 3,188); SetTile(22,34, 3,188); SetTile(22,35, 3,188); SetTile(22,36, 3,188); SetTile(22,37, 3,188); SetTile(22,38, 3,188); SetTile(22,39,3,169);
	   //grate
	   SetTile(21,38, 1, 205); SetTile(21,39, 1, 205); SetTile(22,38, 1, 205); SetTile(22,39, 1, 205); 
	   //sewage OFF at 35,31
	   SetTile(35,31, 3, 0); SetTile(35,32, 3, 0); SetTile(35,33, 3, 0); SetTile(35,34, 3, 0); SetTile(35,35, 3, 0); SetTile(35,36, 3, 0);SetTile(35,37, 3, 0); SetTile(35,38,3,0); SetTile(35,39,3,0);
	   SetTile(36,31, 3, 0); SetTile(36,32, 3, 0); SetTile(36,33, 3, 0); SetTile(36,34, 3, 0); SetTile(36,35, 3, 0); SetTile(36,36, 3, 0); SetTile(36,37, 3, 0); SetTile(36,38,3,0); SetTile(36,39,3,0);
	   //grate
	   SetTile(35,38,1, 101); SetTile(35,39,1, 101); SetTile(36,38,1, 101);  SetTile(36,39,1, 101); 
	}
}


function yellowswitch()
{
	if (!switches[003])
	{
	   switches[003] = 1;	
	   SetTile(4, 39, 1, 95);	//switch down

	   getter("Throw-2.ogg").play(false);	
	   
	   if (switches[004])
	   {
	   //sewege OFF at 54,32
	   SetTile(54,32, 3, 0); SetTile(54,33, 3, 0); SetTile(54,34, 3, 0); 
	   SetTile(55,32, 3, 0); SetTile(55,33, 3, 0); SetTile(55,34, 3, 0);
	   //grate
	   SetTile(54,34, 1, 101); SetTile(55,34, 1, 101);
	   SetTile(54,35, 1, 101); SetTile(55,35, 1, 101);
	   }
	  
	}
	else
	{
	  switches[003] = 0;
	  SetTile(4, 39, 1, 60);	//switchup
	  
	   getter("Throw-2.ogg").play(false);	
	   
	   //sewege ON at 54,32
	   SetTile(54,32, 3,172); SetTile(54,33, 3,172); SetTile(54,34, 3,166);
	   SetTile(55,32, 3,188); SetTile(55,33, 3,169); SetTile(55,34, 3,188);
	   //grate
	   SetTile(54,34, 1, 205); SetTile(55,34, 1, 205);
	   SetTile(54,35, 1, 205); SetTile(55,35, 1, 205);
	}
}


function greenswitch()
{
	if (!switches[004])
	{
	   switches[004] = 1;	
	   SetTile(48, 20, 1, 128); SetTile(48, 21, 1, 129);	//switch down
	   SetTile(57,4,1,126); SetTile(57,5,1,127);	//other up

	   getter("Throw-2.ogg").play(false);	
	   
	   if (switches[003])	//must have yellow switch down too
	   {
	   //sewege OFF at 54,32
	   SetTile(54,32, 3, 0); SetTile(54,33, 3, 0); SetTile(54,34, 3, 0); 
	   SetTile(55,32, 3, 0); SetTile(55,33, 3, 0); SetTile(55,34, 3, 0);
	   //grate
	   SetTile(54,34, 1, 101); SetTile(55,34, 1, 101);
	   SetTile(54,35, 1, 101); SetTile(55,35, 1, 101);
	   }
	   //sewage ON at 61,4
	   SetTile(61,4,3, 172); SetTile(61,5,3, 172);  SetTile(61,6,3, 166); 
	   SetTile(62,4,3, 188); SetTile(62,5,3, 188);  SetTile(62,6,3, 169); 
	   //grate
	   SetTile(61,6,1,205);SetTile(62,6,1,205);SetTile(61,7,1,205);SetTile(62,7,1,205);
	  
	}
	else
	{
	  switches[004] = 0;
	   SetTile(48, 20, 1, 126); SetTile(48, 21, 1, 127);	//switch up
	   SetTile(57,4,1,128); SetTile(57,5,1,129);	//other down

	   getter("Throw-2.ogg").play(false);	
	   
	   //sewege ON at 54,32
	   SetTile(54,32, 3,172); SetTile(54,33, 3,172); SetTile(54,34, 3,166);
	   SetTile(55,32, 3,188); SetTile(55,33, 3,188); SetTile(55,34, 3,169);
	   //grate
	   SetTile(54,34, 1, 205); SetTile(55,34, 1, 205);
	   SetTile(54,35, 1, 205); SetTile(55,35, 1, 205);
	   
	   //sewage OFF at 61,4
	   SetTile(61,4,3, 0); SetTile(61,5,3, 0);  SetTile(61,6,3, 0); 
	   SetTile(62,4,3, 0); SetTile(62,5,3, 0);  SetTile(62,6,3, 0)
	   //grate
	   SetTile(61,6,1,101);SetTile(62,6,1,101);SetTile(61,7,1,101);SetTile(62,7,1,101);
	}
}

function orangeswitch()
{
	if (eventBox['vicks_split'].inprog)
	{
		eventBox['sewerboss01'].play();
	
	}
	//else do the sewage flow for kicks later on
}